//
//  HomeCell.swift
//  BQWB
//
//  Created by laibingqiang on 16/10/26.
//  Copyright © 2016年 laibingqiang. All rights reserved.
//

import UIKit

class HomeCell: UITableViewCell {

    
    var bottomVcon:Constraint?
    
    var statusViewModel:HomeStatusViewModel?{
        
        didSet{
            //原创微博模型赋值
            originalV.model = statusViewModel
            //转发微博模型赋值
            //让约束失效
            bottomVcon?.uninstall()
            if statusViewModel?.isRetweeted_status == false{
                
                bottomV.snp_updateConstraints(closure: { (make) in
                    
                   self.bottomVcon = make.top.equalTo(originalV.snp_bottom).constraint
                })
                forwardV.isHidden = true
            }
            else
            {
                bottomV.snp_updateConstraints(closure: { (make) in
                    self.bottomVcon = make.top.equalTo(forwardV.snp_bottom).constraint
                })
                forwardV.isHidden = false
                forwardV.model = statusViewModel
            }
            
            //底部按钮模型赋值
            bottomV.model = statusViewModel
            
        }
    }
    override init(style: UITableViewCellStyle, reuseIdentifier: String?) {
        
        super.init(style: style, reuseIdentifier: reuseIdentifier)
        
        setupUI()
    }
    
    required init?(coder aDecoder: NSCoder) {
        fatalError("init(coder:) has not been implemented")
    }
    
    func setupUI(){
        //添加子控件
        contentView.addSubview(originalV)
        
        contentView.addSubview(forwardV)
        
        contentView.addSubview(bottomV)
        //设置约束
        originalV.snp_makeConstraints { (make) in
            
            make.top.left.right.equalTo(contentView)
            
           // make.height.equalTo(80)
        }
        
        forwardV.snp_makeConstraints { (make) in
            
            make.left.right.equalTo(contentView)
            make.top.equalTo(originalV.snp_bottom)
            //make.height.equalTo(80)
            
        }
        
        bottomV.snp_makeConstraints { (make) in
            
            make.left.right.bottom.equalTo(contentView)
            
            self.bottomVcon = make.top.equalTo(forwardV.snp_bottom).constraint
            
            make.height.equalTo(35)
            
            make.bottom.equalTo(contentView)
        }
        
    }
    //懒加载
    //原创微博视图
    private lazy var originalV:HomeOriginalView = {
        
        let v = HomeOriginalView()
        v.backgroundColor = UIColor.white
        
        return v
        
    }()
    //转发微博视图
    private lazy var forwardV:HomeForwardView = {
        
        let v = HomeForwardView()
        //v.backgroundColor = UIColor.blue
        
        return v
        
    }()
    
    //底部按钮视图
    private lazy var bottomV:HomeBtnView = {
        
        let v = HomeBtnView()
        
        //v.backgroundColor = UIColor.yellow
        
        return v
        
    }()
}
